<!--在途订单-->
<template>
  <div class="carry-order-box">
    <el-form
      class="clearfix"
      ref="myCusterFormRef"
      :model="Form"
      label-position="left"
      label-width="1rem"
    >
      <!--          <sim-form :Form="Form" isbtn @queryMethods="searchFun"></sim-form>-->
      <sim-form :Form="Form" isbtn @queryMethods="getqryCustList()"></sim-form>
    </el-form>
    <DicTable
      ref="carordertable"
      stripe
      highlight-current-row
      highlight-hover-row
      border
      header-row-class-name="header-row-class"
      row-class-name="ne-row-class"
      :columnData="carOrdertbs.tableColumns"
      :tableData="carOrdertbs.tableData"
      :loading="carOrdertbs.tableLoading"
      :currentPage="carOrdertbs.tablePage.currentPage"
      :pageSize="carOrdertbs.tablePage.pageSize"
      :totalResult="carOrdertbs.tablePage.totalResult"
      :pager="true"
      @on-page-change="handlePageChange"
      @cell-click="Onrowclick"
      resizable
    >
    <template #custSoNumber="{ row }">
      <el-link type="primary">{{row.custSoNumber + '-' + row.batchNbr}}</el-link>
    </template>
    </DicTable>
  </div>
</template>

<script>
import DicTable from "@/components/public/DicTable";
import CommonUtil from "@/utils/common";
import OrderService from "@/api/order/OrderService.js";
import SimForm from "@/components/public/SimForm";
import { mapState, mapGetters } from "vuex";
export default {
  name: "CarryOrder",
  // inheritAttrs: false,
  // props: {
  //   abc:{
  //     type: String
  //   }
  // },
  data() {
    return {
      Form: {
        /**
         * type类型
         *         jmIpt精确模糊 input
         *         Ipt普通 input
         *         select 选择框
         *
         */
        //订单流水号  待定 ，显示是受理流水
        custSoNumber: {
          type: "jmIpt",
          cName: "订单流水号",
          cValue: "",
          oValue: 'T',
          colspan:6,
          opt:[{label:'精确',value:'T'},{label:'模糊',value:'F'}]
        },
        //IDC群号
        groupNbr: {
          type: "Ipt",
          cName: "IDC群号",
          cValue: "",
          colspan:6,
        },
        // 单据类型
        custOrderType: {
          type: "select",
          cName: "单据类型",
          cValue: "",
          colspan:sessionStorage.getItem('proFlag') == '5G' ? 5:6,
          opt: [
            { label: "", value: "" },
            { label: "新装", value: "50200001" },
            { label: "非正常变更", value: "50200002" },
            { label: "正常变更", value: "50200003" },
            { label: "补点", value: "50200004" },
            { label: "拆机", value: "50200005" },
            { label: "补单", value: "50200007" },
          ],
        },
        //5G显示销售品名称字段
        prodIdList:{
          type:sessionStorage.getItem('proFlag') == '5G' ? "select_5G" : '',
          cName: "销售品名称",
          cValue: "",
          colspan:5,
          opt: [
            { label: "", value: "" },
          ],
        }
      },
      // 订单order列表
      carOrdertbs: {
        tableColumns: [
          { slotName: "custSoNumber", title: "流水号" },
          { field: "custOrderTypeName", title: "单据类型" },
          { slotName: "createDate", title: "受理日期" },
          { field: "audDate", title: "审核日期" },
          { field: "custManagerName", title: "客户经理" },
          { field: "busiManagerName", title: "项目经理" },
          { field: "groupNbr", title: "IDC群号" },
        ],
        tableData: [],
        tableLoading: false,
        tablePage: {
          currentPage: 1,
          pageSize: 10,
          totalResult: 0,
        },
      },
    };
  },
  components: {
    DicTable,
    SimForm,
  },
  async created() {
    await this.getOpt_5G();
    if (this.orderPosInfochange) {
      await this.getqryCustList();
    }
  },
  mounted() {

  },
  computed: {
    // ...mapState({
    //   orderPosInfo:state=>state.orders.orderPosInfo
    // })
    ...mapState("orders", ["orderPosInfo"], ["CARRY_ROW"]),
    ...mapState("user", ["user"]),
    ...mapGetters(["orderPosInfochange"]),
  },
  watch: {
    orderPosInfochange: function () {
      this.getqryCustList();
      this.Form = CommonUtil.formInit(this.Form);
    },
  },
  methods: {
    // 查询列表
    async getqryCustList() {
      if(!this.orderPosInfo.custId){
        // 没选择客户时提示
        this.$confirm("请先选择客户！", "提示", {
          confirmButtonText: "知道了",
          type: "warning",
          showCancelButton: false,
          center: true,
        }).then((done) => {
          done();
        });
        return
      }
      let msJson;
      if(sessionStorage.getItem('proFlag') == '5G'){
        let prodIdList = []
        this.Form['prodIdList'].opt.forEach(ele => {
          if(ele.value){
            prodIdList.push(ele.value);
          }
        });
        msJson = {
          statusCds: this.orderPosInfo.statusCds,
          createStaff: this.user.staffId,
          handleOrgId: this.user.orgId,
          custId: this.orderPosInfo.custId,
          custSoNumber: this.Form.custSoNumber.cValue.trim(),
          groupNbr: this.Form.groupNbr.cValue.trim(),
          prodIdList:this.Form.prodIdList.cValue ? this.Form.prodIdList.cValue : prodIdList.join(','),
          custOrderType: this.Form.custOrderType.cValue,
          pageInfo: {
            pageIndex : this.carOrdertbs.tablePage.currentPage,
            pageSize : this.carOrdertbs.tablePage.pageSize
          }
        };
      }else {
        msJson = {
          statusCds: this.orderPosInfo.statusCds,
          createStaff: this.user.staffId,
          handleOrgId: this.user.orgId,
          custId: this.orderPosInfo.custId,
          custSoNumber: this.Form.custSoNumber.cValue.trim(),
          groupNbr: this.Form.groupNbr.cValue.trim(),
          custOrderType: this.Form.custOrderType.cValue,
          pageInfo: {
            pageIndex : this.carOrdertbs.tablePage.currentPage,
            pageSize : this.carOrdertbs.tablePage.pageSize
          }
        };
      }
      this.carOrdertbs.tableLoading = true;
      if(msJson.custSoNumber!=''){
        msJson.custSoNumberJqFlag=this.Form.custSoNumber.oValue;
      };
      const result = await OrderService.getCarryOrderList({...msJson,});
      this.carOrdertbs.tableLoading = false;
      
      
      this.carOrdertbs.tableData = result.meta.customerOrders;
      this.carOrdertbs.tablePage.currentPage = JSON.parse(
        result.meta.pageInfo.pageIndex
      );
      this.carOrdertbs.tablePage.totalResult = JSON.parse(
        result.meta.pageInfo.rowCount
      );
    },
    handlePageChange({ currentPage, pageSize }) {
      this.carOrdertbs.tablePage.currentPage = currentPage;
      this.carOrdertbs.tablePage.pageSize = pageSize;
      this.getqryCustList();
    },
    Onrowclick(data) {
      
      data.row.rowType="CarryOrder";
      this.$store.commit("orders/SET_CARRY_ROW", data.row);
      let tabConfig = this.$attrs.tabConfig;
      if (tabConfig.editableTabs.length < 2) {
        // let newTabName = ++tabConfig.tabIndex + "";
        tabConfig.editableTabs.push({
          title: "改单订单项列表",
          // name: newTabName,
          name: "ChangeOrder",
          closable: true,
          // content: newTabName % 2 == 0 ? "OrderList" : "ChangeOrder",
          content: "ChangeOrder",
        });
        tabConfig.editableTabsValue = "ChangeOrder";
      } else {
        tabConfig.editableTabsValue = "ChangeOrder";
      }
      this.$emit("changeTab", tabConfig);
    },
    // 销售品名称-5G
    async getOpt_5G() {
      let params = {
        interFaceType: "CPCP",
        sqlId: "20210707002",
        paramStr: "catalogItemId:7111",
      };
      const result = await OrderService.getCustNum(params);
      if (result.meta.resCode == "0") {
        let plist = result.meta.resList.executeSqlResp;
        plist.map((item, index) => {
          item.label = item.offer_name;
          item.value = item.offer_id;
          delete item.TEXT;
          delete item.VALUE;
        });
        plist.unshift({ label: "", value: "" });
        this.Form['prodIdList'].opt = plist;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.radio-mt {
  margin-top: 0.1rem;
}
.select-box {
  width: 1rem;
  padding: 0;
}
</style>
